<template>
  <div>
    <el-table :data="orderList" border stripe
    @expand-change="getDetailOrder">
      <el-table-column type="expand" width="100">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand" prop="props.id">
            <el-form-item label="用户名">
              <span>{{ props.row.detailOrder.userResult }}</span>
            </el-form-item>
            <el-form-item label="收货地址">
              <span>{{ props.row.detailOrder.adderssResult }}</span>
            </el-form-item>
            <el-form-item label="店铺地址">
              <span>{{ props.row.detailOrder.resResult }}</span>
            </el-form-item>
            <el-form-item label=" 店铺名称">
              <span>{{ props.row.restaurant_name }}</span>
            </el-form-item>
            <el-form-item label=" 店铺 ID">
              <span>{{ props.row.restaurant_id }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="id" label="订单ID" width="200" align="center">
      </el-table-column>
      <el-table-column prop="total_amount" label="总价格" width="width">
      </el-table-column>
      <el-table-column prop="status_bar.title" label="订单状态" width="width">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handlerSizeChange"
      @current-change="currentChange"
      :current-page="page"
      :page-sizes="[20, 40, 70]"
      :page-size="limit"
      layout="prev, pager, next, jumper,->,sizes,total"
      :total="totalNum"
      background
    >
      :pager-count="11">
    </el-pagination>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "orderList",
  data() {
    return {
      limit: 20,
      offset: 0,
      page: 1,
      totalNum: 0,
      restaurant_id: "",
    };
  },
  computed: {
    ...mapState({
      orderList: state => state.dataManage.orderList
    })
  },
  mounted() {
    this.getOrderInfo();
  },
  methods: {
    async getOrderInfo() {
      const orderCount = await this.$store.dispatch("dataManage/getOrderCount");
      this.totalNum = orderCount;
      const orderList = await this.$store.dispatch("dataManage/getOrderList", {
        offset: this.offset,
        limit: this.limit,
        restaurant_id: this.restaurant_id
      });
    },
    handlerSizeChange(size) {
      this.limit = size;
      this.getOrderInfo();
    },
    currentChange(page = 1) {
      this.page = page;
      this.offset = this.limit * page;
      this.getOrderInfo();
    },
    //获取订单信息
    async getDetailOrder(row,expandedRows){
      console.log(expandedRows)
      if(expandedRows.length){
        const result = await this.$store.dispatch('dataManage/getDetailOrder',row)
      const detailOrder = {
        adderssResult:result.adderssResult.address,
        userResult:result.userResult.username,
        resResult:result.resResult.address
      }
      this.$nextTick(()=>{
        this.orderList.forEach(item => {
          this.$set(item,'detailOrder',detailOrder)
        })
      })
      }
      
    }
  }
};
</script>

<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
